package com.wx.sftp;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.Session;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Closeable;

/**
 * @author 刘畅
 * @date 2018-12-11 23:22
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Jcraft implements Closeable {
  private ChannelSftp sftp;
  private Session session;

  @Override
  public void close() {
    if (sftp != null && sftp.isConnected()) {
      sftp.disconnect();
    }
    if (session != null && session.isConnected()) {
      session.disconnect();
    }
  }

  boolean isConnected() {
    return sftp.isConnected() && session.isConnected();
  }
}
